package xjf.learn.lambda;

import org.junit.Test;
import xjf.base.entity.Employee;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 需求提出
 *
 * @Author: xjf
 * @Date: 2020/4/9 21:29
 */
public class Test2 {

    /**
     * 数据准备
     */
    private List<Employee> employeeList = Arrays.asList(
            new Employee("张三", 45, 6000),
            new Employee("李四", 20, 7600),
            new Employee("王五", 38, 4900),
            new Employee("赵六", 77, 2000),
            new Employee("田七", 54, 6500)
    );


    /**
     * 需求一：求出员工 List 中，所有年龄大于或等于 35 的人
     */

    /**
     * 传统方式实现
     */
    @Test
    public void test1(){

        List<Employee> resultList = filterAge(this.employeeList);

        for (Employee employee : resultList) {
            System.out.println(employee);
        }
    }

    /**
     * 过滤年龄大于等于 35 的人
     */
    private List<Employee> filterAge(List<Employee> employeeList){
        List<Employee> tempList = new ArrayList<>();

        for (Employee employee : employeeList) {
            if (employee.getAge() >= 35){
                tempList.add(employee);
            }
        }

        return tempList;
    }

    /*============================================================== 分割线 ================================================*/

    /**
     * 需求二: 获取员工工资大于等于 5000 的员工
     */

    /**
     * 传统方式实现
     */
    @Test
    public void test2(){
        List<Employee> resultList = filterSalary(employeeList);

        for (Employee employee : resultList) {
            System.out.println(employee);
        }
    }

    /**
     * 过滤工资大于等于 5000 的员工
     */
    private List<Employee> filterSalary(List<Employee> inputList){
        List<Employee> tempList = new ArrayList<>();

        for (Employee employee : inputList) {
            if (employee.getSalary() >= 5000){
                tempList.add(employee);
            }
        }

        return tempList;
    }
}
